package fr.enssat.tpcloud;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import fr.enssat.tpcloud.dao.UserDao;
import fr.enssat.tpcloud.model.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml"})
@TransactionConfiguration(transactionManager="transactionManager")
public class UnitTest extends TestCase {

    @Autowired
    private UserDao userDao = null;
    
    @Transactional
    @Test
    public void creationUserTest() {
        
        int size = userDao.getAllUser().size();
        
        User newUser = new User();
        newUser.setEmail("test@mail.com");
        newUser.setName("toto");
        userDao.save(newUser);

        int newSize = userDao.getAllUser().size();
        
        assertEquals(size+1, newSize);

    }
}
